<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Crafty - Motion</title>
	<link type="text/css" rel="stylesheet" href="/craftyjs-site.css" />

	<link href='http://fonts.googleapis.com/css?family=Arvo:regular,bold' rel='stylesheet' 	type='text/css'>
	<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600' rel='stylesheet' type='text/css'>
	<link rel="shortcut icon" href="/favicon.ico">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
	<link rel="stylesheet" href="/github.css"/>
	<script type="text/javascript">

		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-23935213-2']);
		_gaq.push(['_trackPageview']);

		(function () {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();

	</script>
</head>
<body>
	<div id = "header-background"> </div>
	<div id = "page-frame">
	<div id="header">
		<nav class="navbar">
  			<div class="container-fluid">
  				<div class="navbar-header">
  					<a class="navbar-brand" href="/"> <img class="logo" src="/images/text-logo.png" /> </a>
  					
				</div>
				<div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
					<ul class="nav navbar-nav">
						<li><a href="/">Home</a></li>
						<li><a href="/getting-started/">Getting started</a></li>
						<li><a href="/documentation/">Documentation</a></li>
						<li><a href="/api/">API</a></li>
						<li><a href="https://groups.google.com/forum/#!forum/craftyjs">Forum</a></li>
						<li><a href="/components/">Components</a></li>
						<li class="emph"><a href="/#install">Download</a></li>
					</ul>
				</div>
			</div>
		</nav>
	</div>


	<div id="main">
		<div id="content" class="container">
			



<div id="docs"><div class="toc-holder" id="doc-nav"><ul id="doc-level-one"><li><a href="events.html">List of Events</a></li><li class="category">Core<ul class="category-list"><li><a href="Crafty.html">Crafty</a></li><li><a href="Crafty Core.html">Crafty Core</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-c.html">Crafty.c()</a></li><li><a href="Crafty-clone.html">Crafty.clone()</a></li><li><a href="Crafty-defineField.html">Crafty.defineField()</a></li><li><a href="Crafty-e.html">Crafty.e()</a></li><li><a href="Crafty-extend.html">Crafty.extend()</a></li><li><a href="Crafty-frame.html">Crafty.frame()</a></li><li><a href="Crafty-getVersion.html">Crafty.getVersion()</a></li><li><a href="Crafty-init.html">Crafty.init()</a></li><li><a href="Crafty-isPaused.html">Crafty.isPaused()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-pause.html">Crafty.pause()</a></li><li><a href="Crafty-s.html">Crafty.s()</a></li><li><a href="Crafty-settings.html">Crafty.settings</a></li><li><a href="Crafty-stage.html">Crafty.stage</a></li><li><a href="Crafty-stop.html">Crafty.stop()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">2D<ul class="category-list"><li><a href="2D.html">2D</a></li><li><a href="AngularMotion.html">AngularMotion</a></li><li><a href="Collision.html">Collision</a></li><li><a href="Crafty-circle.html">Crafty.circle</a></li><li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li><li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li><li><a href="Crafty-isometric.html">Crafty.isometric</a></li><li><a href="Crafty-map.html">Crafty.map</a></li><li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li><li><a href="Crafty-polygon.html">Crafty.polygon</a></li><li><a href="Crafty-raycast.html">Crafty.raycast()</a></li><li><a href="Crafty-rectManager.html">Crafty.rectManager</a></li><li><a href="Gravity.html">Gravity</a></li><li><a href="GroundAttacher.html">GroundAttacher</a></li><li><a href="Motion.html">Motion</a></li><li><a href="Supportable.html">Supportable</a></li></ul></li><li class="category">Animation<ul class="category-list"><li><a href="Crafty-easing.html">Crafty.easing</a></li><li><a href="SpriteAnimation.html">SpriteAnimation</a></li><li><a href="Tween.html">Tween</a></li></ul></li><li class="category">Assets<ul class="category-list"><li><a href="Crafty-asset.html">Crafty.asset()</a></li><li><a href="Crafty-assets.html">Crafty.assets</a></li><li><a href="Crafty-imageWhitelist.html">Crafty.imageWhitelist()</a></li><li><a href="Crafty-load.html">Crafty.load()</a></li><li><a href="Crafty-paths.html">Crafty.paths()</a></li><li><a href="Crafty-removeAssets.html">Crafty.removeAssets()</a></li></ul></li><li class="category">Audio<ul class="category-list"><li><a href="Crafty-audio.html">Crafty.audio</a></li></ul></li><li class="category">Controls<ul class="category-list"><li><a href="Controllable.html">Controllable</a></li><li><a href="Controls.html">Controls</a></li><li><a href="Draggable.html">Draggable</a></li><li><a href="Fourway.html">Fourway</a></li><li><a href="Jumper.html">Jumper</a></li><li><a href="Multiway.html">Multiway</a></li><li><a href="Twoway.html">Twoway</a></li></ul></li><li class="category">Debug<ul class="category-list"><li><a href="Crafty-error.html">Crafty.error()</a></li><li><a href="Crafty-log.html">Crafty.log()</a></li><li><a href="DebugCanvas.html">DebugCanvas</a></li><li><a href="DebugPolygon.html">DebugPolygon</a></li><li><a href="DebugRectangle.html">DebugRectangle</a></li><li><a href="SolidAreaMap.html">SolidAreaMap</a></li><li><a href="SolidHitBox.html">SolidHitBox</a></li><li><a href="VisibleMBR.html">VisibleMBR</a></li><li><a href="WiredAreaMap.html">WiredAreaMap</a></li><li><a href="WiredHitBox.html">WiredHitBox</a></li></ul></li><li class="category">Events<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">Game Loop<ul class="category-list"><li><a href="Crafty-timer.html">Crafty.timer</a></li></ul></li><li class="category">Graphics<ul class="category-list"><li><a href="Canvas.html">Canvas</a></li><li><a href="CanvasLayer.html">CanvasLayer</a></li><li><a href="Color.html">Color</a></li><li><a href="Crafty-assignColor.html">Crafty.assignColor()</a></li><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-createLayer.html">Crafty.createLayer()</a></li><li><a href="Crafty-defaultShader.html">Crafty.defaultShader()</a></li><li><a href="Crafty-domHelper.html">Crafty.domHelper</a></li><li><a href="Crafty-pixelart.html">Crafty.pixelart()</a></li><li><a href="Crafty-sprite.html">Crafty.sprite()</a></li><li><a href="Crafty-WebGLShader.html">Crafty.WebGLShader()</a></li><li><a href="DOM.html">DOM</a></li><li><a href="DomLayer.html">DomLayer</a></li><li><a href="HTML.html">HTML</a></li><li><a href="Image.html">Image</a></li><li><a href="Particles.html">Particles</a></li><li><a href="Renderable.html">Renderable</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Text.html">Text</a></li><li><a href="WebGL.html">WebGL</a></li><li><a href="WebGLLayer.html">WebGLLayer</a></li></ul></li><li class="category">Input<ul class="category-list"><li><a href="AreaMap.html">AreaMap</a></li><li><a href="Button.html">Button</a></li><li><a href="Crafty-findPointerEventTargetByComponent.html">Crafty.findPointerEventTargetByComponent()</a></li><li><a href="Crafty-keyboardDispatch.html">Crafty.keyboardDispatch()</a></li><li><a href="Crafty-keydown.html">Crafty.keydown</a></li><li><a href="Crafty-keys.html">Crafty.keys</a></li><li><a href="Crafty-lastEvent.html">Crafty.lastEvent</a></li><li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li><li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch()</a></li><li><a href="Crafty-mouseWheelDispatch.html">Crafty.mouseWheelDispatch()</a></li><li><a href="Crafty-multitouch.html">Crafty.multitouch()</a></li><li><a href="Crafty-selected.html">Crafty.selected</a></li><li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch()</a></li><li><a href="Keyboard.html">Keyboard</a></li><li><a href="Mouse.html">Mouse</a></li><li><a href="MouseDrag.html">MouseDrag</a></li><li><a href="Touch.html">Touch</a></li></ul></li><li class="category">Misc<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-device.html">Crafty.device</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li></ul></li><li class="category">Model<ul class="category-list"><li><a href="Model.html">Model</a></li></ul></li><li class="category">Scenes<ul class="category-list"><li><a href="Crafty-scene.html">Crafty.scene()</a></li></ul></li><li class="category">Stage<ul class="category-list"><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-scene.html">Crafty.scene()</a></li><li><a href="Crafty-viewport.html">Crafty.viewport</a></li></ul></li><li class="category">Utilities<ul class="category-list"><li><a href="Crafty-math.html">Crafty.math</a></li><li><a href="Delay.html">Delay</a></li><li><a href="Storage.html">Storage</a></li></ul></li></ul></div><div id="doc-content" class="doc-page-holder"><div class="doc-page"><h1>Motion <span class="page-badge">Component</span></h1><div class="doclet" id="Motion"><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L193-L206">src/spatial/motion.js#L193-L206</a></div><div class="triggered-events"><h4>Events</h4><div class="trigger-list"><dl class="trigger"><dt>Moved <span>[<span class="trigger-data"><span class="obj-name">Old position</span><span class="obj-props"> = { axis: &#x27;x&#x27; | &#x27;y&#x27;, oldValue: Number }</span></span>]</span></dt><dd>When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.</dd></dl><dl class="trigger"><dt>NewDirection <span>[<span class="trigger-data"><span class="obj-name">New direction</span><span class="obj-props"> = { x: -1 | 0 | 1, y: -1 | 0 | 1 }</span></span>]</span></dt><dd>When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.</dd></dl><dl class="trigger"><dt>MotionChange <span>[<span class="trigger-data"><span class="obj-name">Motion property name and old value</span><span class="obj-props"> = { key: String, oldValue: Number }</span></span>]</span></dt><dd>When a motion property has changed a MotionChange event is triggered.</dd></dl></div></div><span class="markdown"><p>Component that allows moving an entity by applying linear velocity and acceleration.
All linear motion values are expressed in pixels per second (e.g. an entity with <code>vx</code> of 1 will move 1px on the x axis each second).</p>
</span><div class="note"><span class="markdown"><p><strong>Note:</strong> Several methods return Vector2D objects that dynamically reflect the entity&#39;s underlying properties.  If you want a static copy instead, use the vector&#39;s <code>clone()</code> method.</p>
</span></div></div><div><h4>Properties</h4><ul class="page-toc"><li><a href="#-ax">.ax</a></li><li><a href="#-ay">.ay</a></li><li><a href="#-dx">.dx</a></li><li><a href="#-dy">.dy</a></li><li><a href="#-vx">.vx</a></li><li><a href="#-vy">.vy</a></li></ul><h4>Methods</h4><ul class="page-toc"><li><a href="#-acceleration">.acceleration()</a></li><li><a href="#-motionDelta">.motionDelta()</a></li><li><a href="#-resetMotion">.resetMotion()</a></li><li><a href="#-velocity">.velocity()</a></li><li><a href="#-ccdbr">.ccdbr()</a></li></ul><div class="doclet" id="-ax"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.ax</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L246-L262">src/spatial/motion.js#L246-L262</a></div><span class="markdown"><p>A property for accessing/modifying the linear acceleration in the x axis.
The acceleration changes the velocity over time.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> ax = ent.ax; <span class="hljs-comment">// retrieve the linear acceleration in the x axis</span>
ent.ax += <span class="hljs-number">1</span>; <span class="hljs-comment">// increase the linear acceleration in the x axis</span>
ent.ax = <span class="hljs-number">0</span>; <span class="hljs-comment">// reset the linear acceleration in the x axis</span></code></pre></span></div></div><div class="doclet" id="-ay"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.ay</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L265-L281">src/spatial/motion.js#L265-L281</a></div><span class="markdown"><p>A property for accessing/modifying the linear acceleration in the y axis.
The acceleration changes the velocity over time.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> ay = ent.ay; <span class="hljs-comment">// retrieve the linear acceleration in the y axis</span>
ent.ay += <span class="hljs-number">1</span>; <span class="hljs-comment">// increase the linear acceleration in the y axis</span>
ent.ay = <span class="hljs-number">0</span>; <span class="hljs-comment">// reset the linear acceleration in the y axis</span></code></pre></span></div></div><div class="doclet" id="-dx"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.dx</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L284-L297">src/spatial/motion.js#L284-L297</a></div><span class="markdown"><p>A number that reflects the change in x (difference between the old &amp; new x) that was applied in the last frame.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> dx = ent.dx; <span class="hljs-comment">// the change of x in the last frame</span></code></pre></span></div></div><div class="doclet" id="-dy"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.dy</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L300-L313">src/spatial/motion.js#L300-L313</a></div><span class="markdown"><p>A number that reflects the change in y (difference between the old &amp; new y) that was applied in the last frame.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> dy = ent.dy; <span class="hljs-comment">// the change of y in the last frame</span></code></pre></span></div></div><div class="doclet" id="-acceleration"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.acceleration()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L407-L430">src/spatial/motion.js#L407-L430</a></div><span class="markdown"><p>Method for accessing/modifying the linear(x,y) acceleration.
The acceleration increases the velocity over time, resulting in ever increasing speed.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Vector2D </span><span class="sig-noun">.acceleration</span></span><span class="sig-seperator">()</span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>The acceleration Vector2D with the properties {x, y} that reflects the acceleration in the <x, y> direction of the entity.</p>
</span></dd></dl></div><span class="markdown"><p>Returns the current acceleration. You can access/modify the properties in order to retrieve/change the acceleration.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> acc = ent.acceleration(); <span class="hljs-comment">//returns the acceleration object</span>
acc.x;       <span class="hljs-comment">// retrieve the acceleration in the x direction</span>
acc.x = <span class="hljs-number">0</span>;   <span class="hljs-comment">// set the acceleration in the x direction</span>
acc.x += <span class="hljs-number">4</span>   <span class="hljs-comment">// add to the acceleration in the x direction</span></code></pre></span></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li></ul></div></div><div class="doclet" id="-motionDelta"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.motionDelta()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L356-L373">src/spatial/motion.js#L356-L373</a></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Vector2D </span><span class="sig-noun">.motionDelta</span></span><span class="sig-seperator">()</span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>A Vector2D with the properties {x, y} that reflect the change in x &amp; y.</p>
</span></dd></dl></div><span class="markdown"><p>Returns the difference between the old &amp; new position that was applied in the last frame.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> deltaY = ent.motionDelta().y; <span class="hljs-comment">// the change of y in the last frame</span></code></pre></span></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li></ul></div></div><div class="doclet" id="-resetMotion"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.resetMotion()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L338-L347">src/spatial/motion.js#L338-L347</a></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">.resetMotion</span></span><span class="sig-seperator">()</span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>this</p>
</span></dd></dl></div><span class="markdown"><p>Reset all linear motion (resets velocity, acceleration, motionDelta).</p>
</span></div><div class="doclet" id="-velocity"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.velocity()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L378-L401">src/spatial/motion.js#L378-L401</a></div><span class="markdown"><p>Method for accessing/modifying the linear(x,y) velocity.
The velocity remains constant over time, unless the acceleration increases the velocity.</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Vector2D </span><span class="sig-noun">.velocity</span></span><span class="sig-seperator">()</span></code><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>The velocity Vector2D with the properties {x, y} that reflect the velocities in the <x, y> direction of the entity.</p>
</span></dd></dl></div><span class="markdown"><p>Returns the current velocity. You can access/modify the properties in order to retrieve/change the velocity.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> vel = ent.velocity(); <span class="hljs-comment">//returns the velocity vector</span>
vel.x;       <span class="hljs-comment">// retrieve the velocity in the x direction</span>
vel.x = <span class="hljs-number">0</span>;   <span class="hljs-comment">// set the velocity in the x direction</span>
vel.x += <span class="hljs-number">4</span>   <span class="hljs-comment">// add to the velocity in the x direction</span></code></pre></span></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li></ul></div></div><div class="doclet" id="-vx"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.vx</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L208-L224">src/spatial/motion.js#L208-L224</a></div><span class="markdown"><p>A property for accessing/modifying the linear velocity in the x axis.
The velocity remains constant over time, unless the acceleration changes the velocity.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> vx = ent.vx; <span class="hljs-comment">// retrieve the linear velocity in the x axis</span>
ent.vx += <span class="hljs-number">1</span>; <span class="hljs-comment">// increase the linear velocity in the x axis</span>
ent.vx = <span class="hljs-number">0</span>; <span class="hljs-comment">// reset the linear velocity in the x axis</span></code></pre></span></div></div><div class="doclet" id="-vy"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.vy</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L227-L243">src/spatial/motion.js#L227-L243</a></div><span class="markdown"><p>A property for accessing/modifying the linear velocity in the y axis.
The velocity remains constant over time, unless the acceleration changes the velocity.</p>
</span><div class="example"><h4>Example</h4><span class="markdown"><pre><code class="hljs "><span class="hljs-keyword">var</span> ent = Crafty.e(<span class="hljs-string">"2D, Motion"</span>);

<span class="hljs-keyword">var</span> vy = ent.vy; <span class="hljs-comment">// retrieve the linear velocity in the y axis</span>
ent.vy += <span class="hljs-number">1</span>; <span class="hljs-comment">// increase the linear velocity in the y axis</span>
ent.vy = <span class="hljs-number">0</span>; <span class="hljs-comment">// reset the linear velocity in the y axis</span></code></pre></span></div></div><div class="doclet" id="-ccdbr"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">.ccdbr()</h2><div class="doc-source"><a href="https://github.com/craftyjs/Crafty/blob/1ef28454144100272fd439e5c3e8afb90601c00e/src/spatial/motion.js#L435-L453">src/spatial/motion.js#L435-L453</a></div><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Object </span><span class="sig-noun">.ccdbr</span></span><span class="sig-seperator">([</span><span class="sig-phrase"><span class="sig-qualifier">Object </span><span class="sig-noun">ccdbr</span></span><span class="sig-seperator">])</span></code><dl class="parameter"><dt> ccdbr </dt><dd><span class="markdown"><p>an object to use as output</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [Returns] </dt><dd><span class="markdown"><p>an object with <code>_x</code>, <code>_y</code>, <code>_w</code>, and <code>_h</code> properties; if an object is passed in, it will be reused rather than creating a new object.</p>
</span></dd></dl></div><span class="markdown"><p>Return an object containing the entity&#39;s continuous collision detection bounding rectangle.
The CCDBR encompasses the motion delta of the entity&#39;s bounding rectangle since last frame.
The CCDBR is minimal if the entity moved on only one axis since last frame, however it encompasses a non-minimal region if it moved on both axis.
For further details, refer to <a href="https://github.com/craftyjs/Crafty/wiki/Crafty-FAQ-%28draft%29#why-are-my-bullets-passing-through-other-entities-without-registering-hits">FAQ#Tunneling</a>.</p>
</span><div class="note"><span class="markdown"><p><strong>Note:</strong> The keys have an underscore prefix. This is due to the x, y, w, h properties being setters and getters that wrap the underlying properties with an underscore (_x, _y, _w, _h).</p>
</span></div><div><h4>See Also</h4><ul class="see-also-list"><li><a href="#-motionDelta">.motionDelta</a></li><li><a href="Collision.html#-cbr">Collision.cbr</a></li></ul></div></div></div></div></div></div>
			
		</div>
	</div>
	<div class="clearer"></div>
	<div id="footer">
		<div id="contact">
			<a href="https://groups.google.com/forum/#!forum/craftyjs">
				<img src="/images/google.png" />
				google groups</a>
			<a href="mailto:starwed@gmail.com">
				<img src="/images/email.png" />
				starwed@gmail.com</a>
			<a href="https://github.com/craftyjs/Crafty">
				<img src="/images/github.png" />
				github</a>
		</div>
		<ul>
			<li><a href="/">Home</a></li>
				<li><a href="/getting-started/">Getting started</a></li>
				<li><a href="/documentation/">Documentation</a></li>
				<li><a href="/api/">API</a></li>
				<li><a href="https://groups.google.com/forum/#!forum/craftyjs">Forum</a></li>
				<li><a href="/components/">Modules</a></li>
				<li class="emph"><a href="/#install">Download</a></li>
		</ul>
		<p>
			&copy; Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a>.
		</p>
	</div>
</div>
</body>
</html>
